package com.disease.chronic.Mappers;

import com.disease.chronic.pojo.IndicatorsDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface IndicatorsDetailMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(IndicatorsDetail record);

    int insertSelective(IndicatorsDetail record);

    IndicatorsDetail selectByPrimaryKey(Integer id);

    @Select("SELECT ID, INDICATORNAME, DAY, VALUE, USERNAME FROM \"INDICATORSDETAIL\" " +
            "WHERE INDICATORNAME = #{indicatorName} " +
            "AND USERNAME = #{username} AND DAY = #{day}")
    @Results({
            @Result(column = "ID", property = "id"),
            @Result(column = "INDICATORNAME", property = "indicatorName"),
            @Result(column = "DAY", property = "day"),
            @Result(column = "USERNAME", property = "username"),
            @Result(column = "VALUE", property = "value")
    })
    IndicatorsDetail selectByUsernameAndIndicatorNameAndDay(@Param("username") String username
            , @Param("indicatorName") String indicatorName
            , @Param("day") Date day);


    @Select("SELECT ID, INDICATORNAME, DAY, VALUE, USERNAME FROM \"INDICATORSDETAIL\" " +
            "WHERE INDICATORNAME = #{indicatorName} " +
            "AND USERNAME = #{username}")
    @Results({
            @Result(column = "ID", property = "id"),
            @Result(column = "INDICATORNAME", property = "indicatorName"),
            @Result(column = "DAY", property = "day"),
            @Result(column = "USERNAME", property = "username"),
            @Result(column = "VALUE", property = "value")
    })
    List<IndicatorsDetail> selectIndicatorByUsernameAndIndicatorName(@Param("username") String username,
                                                                     @Param("indicatorName") String indicatorName);


    @Select("SELECT ID, INDICATORNAME, DAY, VALUE, USERNAME FROM \"INDICATORSDETAIL\" " +
            "WHERE USERNAME = #{username} " +
            "AND DAY = #{day}")
    @Results({
            @Result(column = "ID", property = "id"),
            @Result(column = "INDICATORNAME", property = "indicatorName"),
            @Result(column = "DAY", property = "day"),
            @Result(column = "USERNAME", property = "username"),
            @Result(column = "VALUE", property = "value")
    })
    List<IndicatorsDetail> selectIndicatorByUsernameAndDay(@Param("username") String username,
                                                           @Param("day") java.sql.Date day);

    int updateByPrimaryKeySelective(IndicatorsDetail record);

    int updateByPrimaryKey(IndicatorsDetail record);
}
